package com.eam.dao.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;

import com.eam.bean.Assetallocation;
import com.eam.dao.AssetallocationDAO;

/**
 * A data access object (DAO) providing persistence and search support for
 * Assetallocation entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.eam.dao.Assetallocation
 * @author MyEclipse Persistence Tools
 */

public class AssetallocationDAOImpl extends AssetallocationDAO {
	private static final Log log = LogFactory.getLog(AssetallocationDAOImpl.class);
	// property constants
	public static final String USER_ID = "userId";
	public static final String ASSET_ID = "assetId";
	public static final String STATUS = "status";
	public static final String NUMBER = "number";
	public static final String BEIZU1 = "beizu1";
	public static final String BEIZHU2 = "beizhu2";

	protected void initDao() {
		// do nothing
	}

	public void save(Assetallocation transientInstance) {
		log.debug("saving Assetallocation instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Assetallocation persistentInstance) {
		log.debug("deleting Assetallocation instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Assetallocation findById(java.lang.Integer id) {
		log.debug("getting Assetallocation instance with id: " + id);
		try {
			Assetallocation instance = (Assetallocation) getHibernateTemplate()
					.get("com.eam.dao.Assetallocation", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Assetallocation instance) {
		log.debug("finding Assetallocation instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Assetallocation instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from Assetallocation as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByUserId(Object userId) {
		return findByProperty(USER_ID, userId);
	}

	public List findByAssetId(Object assetId) {
		return findByProperty(ASSET_ID, assetId);
	}

	public List findByStatus(Object status) {
		return findByProperty(STATUS, status);
	}

	public List findByNumber(Object number) {
		return findByProperty(NUMBER, number);
	}

	public List findByBeizu1(Object beizu1) {
		return findByProperty(BEIZU1, beizu1);
	}

	public List findByBeizhu2(Object beizhu2) {
		return findByProperty(BEIZHU2, beizhu2);
	}

	public List findAll() {
		log.debug("finding all Assetallocation instances");
		try {
			String queryString = "from Assetallocation";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Assetallocation merge(Assetallocation detachedInstance) {
		log.debug("merging Assetallocation instance");
		try {
			Assetallocation result = (Assetallocation) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Assetallocation instance) {
		log.debug("attaching dirty Assetallocation instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Assetallocation instance) {
		log.debug("attaching clean Assetallocation instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static AssetallocationDAOImpl getFromApplicationContext(
			ApplicationContext ctx) {
		return (AssetallocationDAOImpl) ctx.getBean("AssetallocationDAO");
	}
}